package com.yanqu.road.entity.activity.daomu.skillstrategy.passive.impl;

import com.yanqu.road.entity.activity.daomu.DaoMuAttribute;
import com.yanqu.road.entity.activity.daomu.config.DaoMuSkillConfig;
import com.yanqu.road.entity.activity.daomu.enums.DaoMuAttributeEnum;
import com.yanqu.road.entity.activity.daomu.skillstrategy.passive.ISkillPassiveStrategy;
import com.yanqu.road.entity.activity.daomu.skillstrategy.passive.req.DaoMuPassiveSkillCountAttributeReq;
import com.yanqu.road.utils.string.StringUtils;

/**
 * 摸金符
 */
public class SkillTouchGoldStrategy implements ISkillPassiveStrategy {

    /**
     * 计算属性MAP
     * @param req
     */
    @Override
    public void countAttribute(DaoMuPassiveSkillCountAttributeReq req) {
        //技能配置
        DaoMuSkillConfig daoMuSkillConfig = req.getDaoMuSkillConfig();
        String[] skillParaArr = daoMuSkillConfig.getSkillPara().split("\\|");
        //增加攻击力千分比
        long addAttRate = Long.parseLong(skillParaArr[14]);
        //特殊加成
        String specialParamStr = skillParaArr[15];
        if (!StringUtils.isNullOrEmpty(specialParamStr) && !specialParamStr.equals("0")) {
            String[] paramArr = specialParamStr.split(";");
            long timeAddAttRate = Long.parseLong(paramArr[0]);//每次加多少
            int timeAddAttTime = Integer.parseInt(paramArr[1]);//没多少毫秒加一次
            int timeAddAttMaxTime = Integer.parseInt(paramArr[2]);//最多加多少次
            //技能升级后，到现在经历过多少毫秒
            int skillUpgradeTime = req.getDaoMuSkill().getGameMillisecond();
            int gameMillisecond = req.getGameMillisecond();
            int diffTime = gameMillisecond - skillUpgradeTime;
            //加多少次
            int addTime = diffTime / timeAddAttTime;
            if (addTime > timeAddAttMaxTime) {
                addTime = timeAddAttMaxTime;
            }
            addAttRate += timeAddAttRate * addTime;
        }
        //攻击属性
        DaoMuAttribute attAttribute = req.getAttributeMap().get(DaoMuAttributeEnum.ATTRIBUTE_ATT.getType());
        attAttribute.addAddRate(addAttRate);
    }
}
